<?php

namespace App\Pay;

use App\Identity\Pay;
use App\Jobs\RetailJob;
use App\Models\Order;
use App\Models\User;
use Illuminate\Support\Facades\DB;

class Money implements Pay
{
    public function handel(Order $order,User $user, float $amount=0)
    {
        DB::beginTransaction();
        try {
            //1.更新支付状态
            $order->pay_time = date('Y-m-d H:i:s');
            $order->pay_money = $amount;
            $order->pay_status = Order::PAYSTATUS;
            $order->save();
            //2.扣除用户余额
            $user->money = $user->money - $amount;
            $user->save();
            DB::commit();
        }catch (\Exception $e) {
            DB::rollBack();
        }


    }
}
